package com.youshuit.designmodedemo.service.impl.factory;

import com.youshuit.designmodedemo.module.po.PayResult;
import com.youshuit.designmodedemo.module.po.RefundResult;
import com.youshuit.designmodedemo.enumx.PayStatus;
import com.youshuit.designmodedemo.service.IPaymentService;

import java.math.BigDecimal;

public class CmbPaymentServiceImpl implements IPaymentService {

    @Override
    public PayResult pay(String orderId, BigDecimal amount) {
        System.out.println("使用招商银行支付，金额：" + amount);
        // 模拟招商银行支付逻辑
        String tradeNo = "CMB" + System.currentTimeMillis();

        // 这里应该是真实的招商银行支付API调用
        boolean success = Math.random() > 0.2; // 模拟80%成功率

        if (success) {
            return new PayResult(true, "招商银行支付成功", tradeNo, orderId);
        } else {
            return new PayResult(false, "招商银行支付失败", null, orderId);
        }
    }

    @Override
    public RefundResult refund(String orderId, BigDecimal amount) {
        System.out.println("招商银行退款，订单：" + orderId + "，金额：" + amount);
        String refundNo = "CMB_REFUND" + System.currentTimeMillis();
        return new RefundResult(true, "招商银行退款成功", refundNo);
    }

    @Override
    public PayStatus queryPayStatus(String orderId) {
        System.out.println("查询招商银行支付状态，订单：" + orderId);
        return PayStatus.SUCCESS;
    }
}
